const LogModel = require('../../model/Log');
const moment = require('moment')
const qr_image = require('qr-image');

module.exports = {

    QR: async (req, res, next) => {
        try {
            console.log(req.query)
            const temp_qrcode = qr_image.image(req.query.data);
            res.type("png");
            temp_qrcode.pipe(res);
        } catch (e) {
            next(e)
        }
    },

    getOneVoucherQR: async (req, res, next) => {
        try {
            redisClient.get(req.query.token, function (err, data) {
                if (data == null) {
                    res.send({ 'code': 401 })
                    return false
                } else {
                    let openid = JSON.parse(data).openid
                    let timestamp = new Date().getTime()
                    let QRtxt = "openid=" + openid + "&voucher=" + req.query.voucher + "&tms=" + timestamp
                    const temp_qrcode = qr_image.image(QRtxt);
                    res.type("png");
                    temp_qrcode.pipe(res);
                }
            })
        } catch (e) {
            next(e)
        }
    },


};